package com.travel.controller.admin;

import com.travel.common.result.Result;
import com.travel.common.utils.AliOSSUpload;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/upload")
@RequiredArgsConstructor
@CrossOrigin
public class UploadController {

    private final AliOSSUpload aliOSSUpload;

    @PostMapping("/image")
    public String uploadImage(@RequestParam("file") MultipartFile file) {
        // 上传到 OSS
        try {
            String s = aliOSSUpload.uploadFile(file);
            System.out.println(s);
            System.out.println(s.length());
            return s;
        } catch (Exception e) {
            // 记录日志
            System.err.println("文件上传到OSS失败: " + e.getMessage());
            return null;
        }
    }
}